package com.zx.kitchen.index.common.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zx.kitchen.index.R;
import com.zx.kitchen.index.common.entity.PurchaseDataList;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/3.
 */

public class BusinessCenterAdapter extends BaseAdapter {

    private List<PurchaseDataList> objects = new ArrayList<PurchaseDataList>();

    private Context context;
    private LayoutInflater layoutInflater;

    public BusinessCenterAdapter(Context context, List<PurchaseDataList> objects) {
        this.context = context;
        this.objects = objects;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public PurchaseDataList getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.adapter_bussiness, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((PurchaseDataList) getItem(position), (ViewHolder) convertView.getTag(), position);
        return convertView;
    }

    private void initializeViews(PurchaseDataList object, ViewHolder holder, int position) {
        holder.customName.setText("客户名称： " + object.getCustomer_name());
        holder.orderInfoDate.setText(object.getCreate_time());
        holder.tvGoodReceivable.setText("应收金额 ：" + object.getOrder_money()+"元");
        holder.tvGoodsFavourable.setText("商家优惠:" + object.getDiscount_money()+"元");
        holder.tvGoodsNum.setText("商品数 ：" + object.getGoods_count());
        holder.tvGoodsPaidin.setText("实收金额 ：" + object.getReceive_money()+"元");
    }

    protected class ViewHolder {
        private TextView customName;
        private TextView orderInfoDate;
        private TextView tvGoodsNum;
        private TextView tvGoodReceivable;
        private TextView tvGoodsPaidin;
        private TextView tvGoodsFavourable;

        public ViewHolder(View view) {
            customName = (TextView) view.findViewById(R.id.custom_name);
            orderInfoDate = (TextView) view.findViewById(R.id.order_info_date);
            tvGoodsNum = (TextView) view.findViewById(R.id.tv_goods_num);
            tvGoodReceivable = (TextView) view.findViewById(R.id.tv_good_receivable);
            tvGoodsPaidin = (TextView) view.findViewById(R.id.tv_goods_paidin);
            tvGoodsFavourable = (TextView) view.findViewById(R.id.tv_goods_favourable);
        }
    }
}
